<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option label="未审核" :value="1" />
          <el-option label="已通过" :value="2" />
          <el-option label="未通过" :value="3" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >
          搜索结果
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >
          新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >
          修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >
          删除
        </el-button>
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="reportList"
      @selection-change="handleSelectionChange"
      stripe
      border
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="企业名称" align="left" prop="enterpriseName" />
      <el-table-column label="社会信用代码" align="center" prop="creditCode" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 1" type="warning">未审核</el-tag>
          <el-tag v-if="scope.row.status === 2" type="success">已通过</el-tag>
          <el-tag v-if="scope.row.status === 3" type="danger">未通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >
            修改
          </el-button>
          <el-button
            v-if="scope.row.status === 1"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="handleAudit(scope.row)"
          >
            审核
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改报表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-card>
          <div slot="header" class="header">企业基本信息</div>
          <el-form-item label="企业名称" prop="enterpriseName">
            <el-input v-model="form.enterpriseName" placeholder="请输入企业名称" />
          </el-form-item>
          <el-form-item label="统一社会信用代码" prop="creditCode">
            <el-input v-model="form.creditCode" placeholder="请输入统一社会信用代码" />
          </el-form-item>
          <el-form-item label="是否高新技术企业" prop="isHightechEnterprise">
            <el-radio-group v-model="form.isHightechEnterprise">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item
            v-if="form.isHightechEnterprise === 1"
            label="证书编号"
            prop="highTechCertificateNo"
          >
            <el-input v-model="form.highTechCertificateNo" placeholder="请输入高新技术企业证书编号" />
          </el-form-item>
          <el-form-item label="是否科技型中小企业" prop="isTechSmallMedium">
            <el-radio-group v-model="form.isTechSmallMedium">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="在孵企业总收入（千元）" prop="totalIncome">
            <el-input-number v-model="form.totalIncome" :min="0" placeholder="请输入在孵企业总收入" />
          </el-form-item>
          <el-form-item label="在孵企业工业总产值（千元）" prop="industrialOutput">
            <el-input-number v-model="form.industrialOutput" :min="0" placeholder="请输入在孵企业工业总产值" />
          </el-form-item>
          <el-form-item label="在孵企业净利润（千元）" prop="netProfit">
            <el-input-number v-model="form.netProfit" :min="0" placeholder="请输入在孵企业净利润" />
          </el-form-item>
          <el-form-item label="在孵企业上缴税额（千元）" prop="taxPayment">
            <el-input-number v-model="form.taxPayment" :min="0" placeholder="请输入在孵企业上缴税额" />
          </el-form-item>
          <el-form-item label="在孵企业出口总额（千元）" prop="exportVolume">
            <el-input-number v-model="form.exportVolume" :min="0" placeholder="请输入在孵企业出口总额" />
          </el-form-item>
        </el-card>

        <el-card>
          <div slot="header" class="header">知识产权情况</div>
          <el-form-item label="专利申请数（件）" prop="patentApplication">
            <el-input-number v-model="form.patentApplication" :min="0" placeholder="请输入专利申请数" />
          </el-form-item>
          <el-form-item label="其中：发明专利（件）" prop="inventionPatentApplication">
            <el-input-number v-model="form.inventionPatentApplication" :min="0" placeholder="请输入发明专利申请数" />
          </el-form-item>
          <el-form-item label="专利授权数（件）" prop="patentGranted">
            <el-input-number v-model="form.patentGranted" :min="0" placeholder="请输入专利授权数" />
          </el-form-item>
          <el-form-item label="其中：发明专利（件）" prop="inventionPatentGranted">
            <el-input-number v-model="form.inventionPatentGranted" :min="0" placeholder="请输入发明专利授权数" />
          </el-form-item>
        </el-card>

        <el-card>
          <div slot="header" class="header">在孵企业从业人员情况</div>
          <el-form-item label="在孵企业从业人员（人）" prop="employees">
            <el-input-number v-model="form.employees" :min="0" placeholder="请输入在孵企业从业人员数" />
          </el-form-item>
          <el-form-item label="其中：博士（人）" prop="doctorNum">
            <el-input-number v-model="form.doctorNum" :min="0" placeholder="请输入博士人数" />
          </el-form-item>
          <el-form-item label="硕士（人）" prop="masterNum">
            <el-input-number v-model="form.masterNum" :min="0" placeholder="请输入硕士人数" />
          </el-form-item>
          <el-form-item label="研究生学历（人）" prop="postgraduateNum">
            <el-input-number v-model="form.postgraduateNum" :min="0" placeholder="请输入研究生学历人数" />
          </el-form-item>
          <el-form-item label="本科学历（人）" prop="bachelorNum">
            <el-input-number v-model="form.bachelorNum" :min="0" placeholder="请输入本科学历人数" />
          </el-form-item>
          <el-form-item label="大专学历（人）" prop="collegeNum">
            <el-input-number v-model="form.collegeNum" :min="0" placeholder="请输入大专学历人数" />
          </el-form-item>
          <el-form-item label="中专学历（人）" prop="technicalSchoolNum">
            <el-input-number v-model="form.technicalSchoolNum" :min="0" placeholder="请输入中专学历人数" />
          </el-form-item>
          <el-form-item label="研究开发人员（人）" prop="rdPersonnel">
            <el-input-number v-model="form.rdPersonnel" :min="0" placeholder="请输入研究开发人员数" />
          </el-form-item>
          <el-form-item label="研究与试验发展（R&D）人员（人）" prop="rdPersonnelDetail">
            <el-input-number v-model="form.rdPersonnelDetail" :min="0" placeholder="请输入研究与试验发展（R&D）人员数" />
          </el-form-item>
          <el-form-item label="留学回国人员（人）" prop="returnee">
            <el-input-number v-model="form.returnee" :min="0" placeholder="请输入留学回国人员数" />
          </el-form-item>
          <el-form-item label="接纳大学生、研究生实习人员（人）" prop="internAcceptance">
            <el-input-number v-model="form.internAcceptance" :min="0" placeholder="请输入接纳大学生、研究生实习人员数" />
          </el-form-item>
          <el-form-item label="接纳应届毕业生就业人员（人）" prop="freshGraduateEmployment">
            <el-input-number v-model="form.freshGraduateEmployment" :min="0" placeholder="请输入接纳应届毕业生就业人员数" />
          </el-form-item>
        </el-card>

        <el-card>
          <div slot="header" class="header">科技活动情况</div>
          <el-form-item label="承担各级各类科技计划项目（项）" prop="techProjectTotal">
            <el-input-number v-model="form.techProjectTotal" :min="0" placeholder="请输入承担科技计划项目数" />
          </el-form-item>
          <el-form-item label="其中：国家级项目（项）" prop="nationalTechProject">
            <el-input-number v-model="form.nationalTechProject" :min="0" placeholder="请输入国家级项目数" />
          </el-form-item>
          <el-form-item label="研究开发经费支出总额（千元）" prop="rdExpenditureTotal">
            <el-input-number v-model="form.rdExpenditureTotal" :min="0" placeholder="请输入研究开发经费支出总额" />
          </el-form-item>
          <el-form-item label="研究与试验发展（R&D）经费支出（千元）" prop="rdExpenditure">
            <el-input-number v-model="form.rdExpenditure" :min="0" placeholder="请输入研究与试验发展（R&D）经费支出" />
          </el-form-item>
          <el-form-item label="新产品开发经费支出（千元）" prop="newProductDevExpenditure">
            <el-input-number v-model="form.newProductDevExpenditure" :min="0" placeholder="请输入新产品开发经费支出" />
          </el-form-item>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 审核对话框 -->
    <el-dialog :title="'审核 - ' + auditForm.enterpriseName" :visible.sync="auditOpen" width="50%" append-to-body>
      <el-form ref="auditForm" :model="auditForm" :rules="auditRules" label-width="120px">
        <el-form-item label="审核状态">
          <el-radio-group v-model="auditForm.status">
            <el-radio :label="2">通过</el-radio>
            <el-radio :label="3">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
<!--        <el-form-item label="审核意见">-->
<!--          <el-input-->
<!--            v-model="auditForm.auditOpinion"-->
<!--            type="textarea"-->
<!--            placeholder="请输入审核意见"-->
<!--          ></el-input>-->
<!--        </el-form-item>-->
        <el-form-item label="报出日期" prop="reportDate">
          <el-date-picker
            v-model="auditForm.reportDate"
            type="date"
            placeholder="选择报出日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd HH:mm:ss"
          />
        </el-form-item>


        <el-form-item label="单位详细名称" prop="companyName" :required="true">
          <el-input v-model="auditForm.companyName" placeholder="请输入单位详细名称" />
        </el-form-item>
        <el-form-item label="单位负责人" prop="companyPrincipal" :required="true">
          <el-input v-model="auditForm.companyPrincipal" placeholder="请输入单位负责人" />
        </el-form-item>
        <el-form-item label="统计负责人" prop="statisticsPrincipal" :required="true">
          <el-input v-model="auditForm.statisticsPrincipal" placeholder="请输入统计负责人" />
        </el-form-item>
        <el-form-item label="填表人" prop="filler" :required="true">
          <el-input v-model="auditForm.filler" placeholder="请输入填表人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone" :required="true">
          <el-input v-model="auditForm.contactPhone" placeholder="请输入联系电话" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAudit">确 定</el-button>
        <el-button @click="cancelAudit">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  GetUserDataSCience,
  AddDataSCience,
  UpdataUserDataSCience,
  DataSCiencedetial,
  DeatalSCiencedetial, GetUserDataSCienceStatusGT0
} from '@/api/system/DataFrom';

export default {
  name: "ScienceParkReport",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报表列表
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示审核弹窗
      auditOpen: false,
      // 查询参数
      queryParams: {
        current: 1,
        pageSize: 10,
        enterpriseName: '',
        status: null
      },
      // 表单参数
      form: {},
      // 审核表单参数
      auditForm: {
        id: null,
        status: null,
        // auditOpinion: null,
        reportDate: null,
        companyName: null,
        companyPrincipal: null,
        statisticsPrincipal: null,
        filler: null,
        contactPhone: null
      },
      // 表单验证规则
      rules: {
        enterpriseName: [
          { required: true, message: "企业名称不能为空", trigger: "blur" }
        ],
        creditCode: [
          { required: true, message: "统一社会信用代码不能为空", trigger: "blur" }
        ],

      },
      // 审核表单验证规则
      auditRules: {

        companyName: [
          { required: true, message: "单位详细名称不能为空", trigger: "blur" }
        ],
        companyPrincipal: [
          { required: true, message: "单位负责人不能为空", trigger: "blur" }
        ],
        statisticsPrincipal: [
          { required: true, message: "统计负责人不能为空", trigger: "blur" }
        ],
        filler: [
          { required: true, message: "填表人不能为空", trigger: "blur" }
        ],
        contactPhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询报表列表 *//** 查询报表列表 */
    getList() {
      this.loading = true;
      GetUserDataSCienceStatusGT0(this.queryParams).then(response => {
        // 过滤掉状态为0的数据
        this.reportList = response.data.records.filter(item => item.status !== 0);
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 审核取消按钮
    cancelAudit() {
      this.auditOpen = false;
      this.resetAudit();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        enterpriseName: null,
        creditCode: null,
        isHightechEnterprise: 0,
        highTechCertificateNo: null,
        isTechSmallMedium: 0,
        totalIncome: 0,
        industrialOutput: 0,
        netProfit: 0,
        taxPayment: 0,
        exportVolume: 0,
        reportDate: null,
        patentApplication: 0,
        inventionPatentApplication: 0,
        patentGranted: 0,
        inventionPatentGranted: 0,
        employees: 0,
        doctorNum: 0,
        masterNum: 0,
        postgraduateNum: 0,
        bachelorNum: 0,
        collegeNum: 0,
        technicalSchoolNum: 0,
        rdPersonnel: 0,
        rdPersonnelDetail: 0,
        returnee: 0,
        internAcceptance: 0,
        freshGraduateEmployment: 0,
        techProjectTotal: 0,
        nationalTechProject: 0,
        rdExpenditureTotal: 0,
        rdExpenditure: 0,
        newProductDevExpenditure: 0
      };
      this.resetForm("form");
    },
    // 审核表单重置
    resetAudit() {
      this.auditForm = {
        id: null,
        status: null,
        reportDate: null,
        companyName: null,
        companyPrincipal: null,
        statisticsPrincipal: null,
        filler: null,
        contactPhone: null
      };
      this.resetForm("auditForm");
    },
    /** 搜索有用功能 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮功能 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加报表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      DataSCiencedetial(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报表";
      });
    },
    /** 审核按钮操作 */
    handleAudit(row) {
      this.resetAudit();
      this.auditForm.id = row.id;
      this.auditForm.enterpriseName = row.enterpriseName;
      this.auditOpen = true;
    },
    /** 提交审核 */
    submitAudit() {
      this.$refs["auditForm"].validate(valid => {
        if (valid) {
          const data = {
            id: this.auditForm.id,
            status: this.auditForm.status,
            // auditOpinion: this.auditForm.auditOpinion,
            reportDate: this.auditForm.reportDate,
            companyName: this.auditForm.companyName,
            companyPrincipal: this.auditForm.companyPrincipal,
            statisticsPrincipal: this.auditForm.statisticsPrincipal,
            filler: this.auditForm.filler,
            contactPhone: this.auditForm.contactPhone
          };
          UpdataUserDataSCience(data).then(response => {
            console.log(data);
            this.$modal.msgSuccess("审核成功");
            this.auditOpen = false;
            this.getList();
          });
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            UpdataUserDataSCience(this.form).then(response => {

              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            // 新增时默认状态为未审核（1）
            this.form.status = 1;
            console.log(this.form);
            AddDataSCience(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除所选的报表？")
        .then(() => {
          return DeatalSCiencedetial(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    }
  }
};
</script>

<style scoped>
.header {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 20px;
}
.el-card {
  margin-bottom: 20px;
}
</style>
